package com.example.onlinemusic.service;

import com.example.onlinemusic.mapper.LoveMusicMapper;
import com.example.onlinemusic.mapper.MusicMapper;
import com.example.onlinemusic.mapper.UserMapper;
import com.example.onlinemusic.model.Music;
import com.example.onlinemusic.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private MusicMapper musicMapper;

    @Autowired
    private LoveMusicMapper loveMusicMapper;


    //注册
    public int addUser(User user){
        return userMapper.addUser(user);
    }

    public User login(User userlogin){
        return userMapper.login(userlogin);
    }

    public User selectByName(String username){
        return userMapper.selectByName(username);
    }

    public int insertMusic(String title, String singer, String time, String url,int userid){
        return musicMapper.insertMusic(title,singer,time,url,userid);
    }

    public Music selectinsertMusic(String title, String singer){
        return musicMapper.selectinsertMusic(title,singer);
    }

    public Music selectMusicById(int id){
        return musicMapper.selectMusicById(id);
    }

    public int deleteMusicById(int id){
        return musicMapper.deleteMusicById(id);
    }

    public List<Music> findMusicByMusicName(String name){
        return musicMapper.findMusicByMusicName(name);
    }

    public List<Music> findMusic(){
        return musicMapper.findMusic();
    }

    public Music findLoveMusicByMusicIdAndUserId(Integer userId,Integer musicId){
        return loveMusicMapper.findLoveMusicByMusicIdAndUserId(userId,musicId);
    }

    public Boolean insertLoveMusic(Integer userId,Integer musicId){
        return loveMusicMapper.insertLoveMusic(userId,musicId);
    }

    public List<Music> findLoveMusicByUserId(int userId){
        return loveMusicMapper.findLoveMusicByUserId(userId);
    }

    public List<Music> findLoveMusicBykeyAndUID(String musicName, int userId){
        return loveMusicMapper.findLoveMusicBykeyAndUID(musicName,userId);
    }

    public int deleteLoveMusic(int userId,int musicId){
        return loveMusicMapper.deleteLoveMusic(userId,musicId);
    }

    public int deleteLoveMusicById(int musicId){
        return loveMusicMapper.deleteLoveMusicById(musicId);
    }
}
